//
//  LJifenMallCommonVC.m
//  CloudClassroom
//
//  Created by dfws on 2019/10/25.
//  Copyright © 2019 dfws. All rights reserved.
//

#import "LJifenMallCommonVC.h"
#import "LJifenMallTableViewCell.h"
#import "BaseTableView.h"
#define kPageCount 20
@interface LJifenMallCommonVC ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
@property (nonatomic, assign) NSInteger currentPage;
@property(nonatomic)BaseTableView *tableView;
@property(nonatomic)NSMutableArray *dataSource;
@end

@implementation LJifenMallCommonVC
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (self.scrollBolock) {
        self.scrollBolock(scrollView.contentOffset.y);
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
//    _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
//    _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreDatas)];
//    [_tableView.mj_header beginRefreshing];
//    [self loadNewsListWith:1];
    // Do any additional setup after loading the view from its nib.
}
- (void)setNowRealScrollHeight:(CGFloat)nowRealScrollHeight{
    _nowRealScrollHeight = nowRealScrollHeight;
    if (_nowRealScrollHeight >= _canScrollHeight) {
        self.tableView.scrollEnabled = YES;
    }else{
        self.tableView.scrollEnabled = NO;
    }
}
//- (void)loadNewDatas
//{
//    [self loadNewsListWith:1];
//}
//
//- (void)loadMoreDatas
//{
//    [self loadNewsListWith:_currentPage + 1];
//}
//- (void)loadNewsListWith:(NSInteger)page
//{
////学分申报记录
//    NSDictionary *parameters = @{@"user_ticket": kUserTicket,@"page": @(page),@"page_size": @(kPageCount),@"range_type":self.range_type};
//    [[LMSAPIClient apiManager] requestUrl:@"mv2/user/goods/list"
//                              parameters:parameters
//                                 success:^(NSURLSessionDataTask *dataTask, id JSON) {
//
//                                     [self.tableView.mj_header endRefreshing];
//                                     [self handleResult:JSON page:page];
//
//                                 } failure:^(NSURLSessionDataTask *dataTask, NSError *error) {
//                                     MyLog(@"%@",error);
//                                     [self.tableView.mj_header endRefreshing];
//                                     [self.tableView.mj_footer endRefreshing];
//                                 }];
//}
//- (void)handleResult:(NSDictionary *)JSON page:(NSInteger)page
//{
//    if ([JSON[@"status"] integerValue]== 1)
//    {
//        _currentPage = page;
//        if (page == 1)
//        {
//            [self.dataSource removeAllObjects];
//        }
//        NSArray * arrayList =JSON[@"data"][@"list"];
//        if (arrayList.count < kPageCount)
//        {
//            [self.tableView.mj_footer endRefreshingWithNoMoreData];
//        }else
//        {
//            [self.tableView.mj_footer endRefreshing];
//        }
//        for (NSDictionary * dic in arrayList)
//        {
//
//                JifenListModel * model = [JifenListModel mj_objectWithKeyValues:dic];
//                [self.dataSource addObject:model];
//
//
//        }
//        [self.tableView reloadData];
//    }else
//    {
//        [self.tableView.mj_footer endRefreshing];
//    }
//}
#pragma mark - UITableViewDataSource, UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    if (!self.dataSource) {
//        return 0;
//    }
//    return self.dataSource.count;
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"LJifenMallTableViewCell" owner:self options:nil];
    LJifenMallTableViewCell *cell = [nibs firstObject];
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 104;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%ld",(long)indexPath.row);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (NSMutableArray *)dataSource
{
    if (!_dataSource) {
        self.dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
@end
